import Vue from "vue";
import VueRouter from "vue-router"

Vue.use(VueRouter)

import peopleMessage from '../views/peopleMessage/index.vue'
import publicPlatform from '../views/publicPlatform/index.vue'
// import teachpublicPlatform from '../views/teachpublicPlatform/index.vue'
import peopleList from '../views/publicPlatform/peopleList/index.vue'
import questionAnalyse from '../views/publicPlatform/questionAnalyse/index.vue'
import questionGroup from '../views/publicPlatform/questionGroup/index.vue'
import shareList from '../views/publicPlatform/shareList/index.vue'

const routes = [
    // 配置路由重定向
    {
      path: '/',
      redirect: '/login'
  },
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/Main'),
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('../views/home')
      },
      {
        path: '/shareQuestions',
        name: 'shareQuestions',
        component: () => import('../views/shareQuestions'),
        children: [
          {
            path: 'shareQues',
            name: 'shareQues',
            component:()=>import('../views/shareQuestions/shareQues')
          },
          {
            path: 'myQues',
            name: 'myQues',
            component:()=>import('../views/shareQuestions/myQues')
          },
        ]
      },
      
      {
        path: '/peopleMessage',
        name: 'peopleMessage',
        component: peopleMessage,
        children: [
          {
            path: 'message1',
            name: 'message1',
            component:()=>import('../views/peopleMessage/views/message1.vue')
          },
          {
            path: 'message2',
            name: 'message2',
            component:()=>import('../views/peopleMessage/views/message2.vue')
          }
        ]
      },
      {
        path: '/teacherClass',
        name: 'teacherClass',
        component: () => import('../views/classManage/teacherClass')
      },
      {
        path: '/addClass',
        name: 'addClass',
        component: () => import('../views/classManage/addClass')
      },
      {
        path: '/studentMessage',
        name: 'studentMessage',
        component: () => import('../views/classManage/studentMessage')
      },
      {
        path: '/add-question',
        name: 'add-question',
        component: () => import('../views/question/add-question')
      },
      {
        path: '/add-knowledge',
        name: 'add-knowledge',
        component: () => import('../views/knowledge/add-knowledge')
      },
      {
        path: '/single',
        name: 'single',
        component: () => import('../views/question/single')
      },
      {
        path: '/multiple',
        name: 'multiple',
        component: () => import('../views/question/multiple')
      },
      {
        path: '/short-answer',
        name: 'short-answer',
        component: () => import('../views/question/short-answer')
      },
      {
        path: '/true-false',
        name: 'true-false',
        component: () => import('../views/question/true-false')
      },
      {
        path: '/gap-filling',
        name: 'gap-filling',
        component: () => import('../views/question/gap-filling')
      },
      {
        path: '/discuss',
        name: 'discuss',
        component: () => import('../views/question/discuss')
      },
      {
        path: '/compute',
        name: 'compute',
        component: () => import('../views/question/compute')
      },
      {
        path: '/information',
        name: 'information',
        component: () => import('../views/question/information')
      },
      {
        path: '/sort',
        name: 'sort',
        component: () => import('../views/question/sort')
      },
      {
        path: '/cloze-test',
        name: 'cloze-test',
        component: () => import('../views/question/cloze-test')
      },
      {
        path: '/reading-comprehension',
        name: 'reading-comprehension',
        component: () => import('../views/question/reading-comprehension')
      },
      {
        path: '/integrated',
        name: 'integrated',
        component: () => import('../views/question/integrated')
      },
      {
        path: '/aiTestPaper',
        name: 'aiTestPaper',
        component: () => import('../views/testPaper/aiTestPaper')
      },
      {
        path: '/peopleTestPaper',
        name: 'peopleTestPaper',
        component: () => import('../views/testPaper/peopleTestPaper')
      },
      {
        path: '/examMessage',
        name: 'examMessage',
        component: () => import('../views/examination/examMessage')
      },
      {
        path: '/mainInvigilate',
        name: 'mainInvigilate',
        component: () => import('../views/examination/mainInvigilate')
      },
      {
        path: '/litterInvigilate',
        name: 'litterInvigilate',
        component: () => import('../views/examination/litterInvigilate')
      },
      {
        path: '/historyPaper',
        name: 'historyPaper',
        component: () => import('../views/examination/historyPaper')
      },
      {
        path: '/paperMessage',
        name: 'paperMessage',
        component: () => import('../views/examination/paperMessage')
      },
      {
        path: '/correctPaper',
        name: 'correctPaper',
        component: () => import('../views/paperManage/correctPaper')
      },
      {
        path: '/achievementStatistic',
        name: 'achievementStatistic',
        component: () => import('../views/achievementAnalysis/achievementStatistic')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login')
  }
]

const router = new VueRouter({
  mode: "history",
  routes,
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { y: 0 }
  },
});

//重写push方法，防止重复点击报错
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
    
   return originalPush.call(this, location).catch(err => err)
}

//路由守卫，路由跳转检验
router.beforeEach((to, from, next) => {
  if (to.name=='login'||to.name!='login'&&sessionStorage.getItem('token')) {
    next();
  }
  else {
    next({ name:'login'})
  }
})



export default router
